new Vue({
    el: '#app',
    data: {
        name: '',
        checkedNames: [],
        amount: '',
        months: '',
        rate: 2,
        loanDate: '',
        manageRate: 1,
        loanType: 'XXHB',
        serveRate: 4,//服务费费率(每笔)
        depositRate: 2,//保证金
        bxyj: 0.00,//保险押金
        carAssessFee: 1500,//车辆评估费
        gpsPledgeFee: 0.00,//GPS押金
        breakRuleFee: 2400,//违章押金
    },
    methods: {
        changeLoanType: function (event) {
            if (this.loanType == 'XXHB') {
                this.rate = 2;
                this.manageRate = 1;
                this.serveRate = 4;
                this.depositRate = 2;
            }
            if (this.loanType == 'DEBX') {
                this.rate = 2;
                this.manageRate = 0;
                this.serveRate = 5;
                this.depositRate = 2;
            }
        },
        changeLoadDate: function (event) {
            this.loanDate = document.getElementById("loanDate").value;
        }
    },
    filters: {
        fixDot: function (value, fix) {
            var v = value.toFixed(fix);
            return v;
        }
    },
    computed: {
        fwf: function () {//服务费
            var fwf = 0.00;
            if (G.isNotEmpty(this.amount) && G.isNotEmpty(this.serveRate)) {
                fwf = this.amount * this.serveRate / 100;
            }
            return fwf;
        },
        bzj: function () {//保证金
            var bzj = 0.00;
            if (G.isNotEmpty(this.amount) && G.isNotEmpty(this.serveRate)) {
                bzj = this.amount * this.depositRate / 100;
            }
            return bzj;
        },
        je: function () {//实际借款金额
            var v = 0.00;
            if (G.isNotEmpty(this.amount)) {
                v = this.amount - this.ysje
            }
            return v;
        },
        ysje: function () {//应收金额
            var v = 0.00;
            if (G.isNotEmpty(this.amount) && G.isNotEmpty(this.serveRate)) {
                v = this.bxyj + this.carAssessFee + this.gpsPledgeFee + this.breakRuleFee + ( this.amount * (this.rate / 100 + this.manageRate / 100)) + this.fwf + this.bzj;
            }
            return v;
        },
        details: function () {
            console.log("xxx");
            this.loanDate = document.getElementById("loanDate").value;
            if (G.isNotEmpty(this.amount) && G.isNotEmpty(this.months) && G.isNotEmpty(this.rate) && G.isNotEmpty(this.manageRate) && G.isNotEmpty(this.loanDate)) {
                var details = [];
                var loanDateStr = this.loanDate;
                var loanDate1 = new XDate(loanDateStr);
                for (var i = 0; i <= this.months; i++) {
                    var detail = {};
                    var dateStr = loanDate1.toString("yyyy-MM-dd");
                    console.log(dateStr);
                    detail.hkrq = dateStr;
                    loanDate1.addMonths(1);
                    if (this.loanType == 'XXHB') {//先息后本
                        var yhkje = this.amount * (this.rate / 100 + this.manageRate / 100);
                        detail.yhkje = yhkje;
                        if (i == this.months) {
                            detail.bj = this.amount;
                        } else {
                            detail.bj = 0.00;
                        }
                        detail.lx = this.amount * this.rate / 100;
                        detail.glf = this.amount * this.manageRate / 100;
                        detail.tcf = 0.00;
                        detail.qt = 0.00;
                    }
                    if (this.loanType == 'DEBX') {//等额本息
                        if (i == 0) {
                            detail.yhkje = this.amount * this.rate / 100
                        } else if (i == this.months) {
                            detail.yhkje = (this.amount / this.months).toFixed(2)
                        } else {
                            detail.yhkje = Number((this.amount / this.months).toFixed(2)) + this.amount * this.rate / 100
                        }
                        detail.bj = (this.amount / this.months).toFixed(2);
                        if (i == this.months) {
                            detail.lx = 0;
                        } else {
                            detail.lx = this.amount * this.rate / 100;
                        }
                        detail.glf = this.amount * this.manageRate / 100;
                        detail.tcf = 0.00;
                        detail.qt = 0.00;
                    }
                    details.push(detail);
                }
                return details;
            } else {
                return [];
            }
        }
    }
});